<?php

namespace app\store\model\shop;

use think\Model;
use traits\model\SoftDelete;

class Auth extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'wanlshop_auth';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'state_text',
        'payment_text',
        'receipt_text',
        'individual_text',
        'contracttime_text',
        'authorization_text',
        'authorizationtime_text',
        'operation_text',
        'guarantee_text',
        'publiccontract_text',
        'publictime_text',
        'orization_text',
        'orizationtime_text',
        'verify_text',
        'status_text'
    ];
    

    
    public function getStateList()
    {
        return [ '1' => __('State 1'), '2' => __('State 2')];
    }

    public function getPaymentList()
    {
        return ['0' => __('Payment 0'), '1' => __('Payment 1')];
    }

    public function getReceiptList()
    {
        return ['0' => __('Receipt 0'), '1' => __('Receipt 1')];
    }

    public function getIndividualList()
    {
        return ['0' => __('Individual 0'), '1' => __('Individual 1')];
    }

    public function getAuthorizationList()
    {
        return ['0' => __('Authorization 0'), '1' => __('Authorization 1')];
    }

    public function getOperationList()
    {
        return ['0' => __('Operation 0'), '1' => __('Operation 1')];
    }

    public function getGuaranteeList()
    {
        return ['0' => __('Guarantee 0'), '1' => __('Guarantee 1')];
    }

    public function getPubliccontractList()
    {
        return ['0' => __('Publiccontract 0'), '1' => __('Publiccontract 1')];
    }

    public function getOrizationList()
    {
        return ['0' => __('Orization 0'), '1' => __('Orization 1')];
    }

    public function getVerifyList()
    {
        return ['0' => __('Verify 0'), '1' => __('Verify 1'), '2' => __('Verify 2'), '3' => __('Verify 3'), '4' => __('Verify 4')];
    }

    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }


    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPaymentTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['payment']) ? $data['payment'] : '');
        $list = $this->getPaymentList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getReceiptTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['receipt']) ? $data['receipt'] : '');
        $list = $this->getReceiptList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIndividualTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['individual']) ? $data['individual'] : '');
        $list = $this->getIndividualList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getContracttimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['contracttime']) ? $data['contracttime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getAuthorizationTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['authorization']) ? $data['authorization'] : '');
        $list = $this->getAuthorizationList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAuthorizationtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['authorizationtime']) ? $data['authorizationtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getOperationTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['operation']) ? $data['operation'] : '');
        $list = $this->getOperationList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getGuaranteeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['guarantee']) ? $data['guarantee'] : '');
        $list = $this->getGuaranteeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPubliccontractTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['publiccontract']) ? $data['publiccontract'] : '');
        $list = $this->getPubliccontractList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPublictimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['publictime']) ? $data['publictime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getOrizationTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['orization']) ? $data['orization'] : '');
        $list = $this->getOrizationList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getOrizationtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['orizationtime']) ? $data['orizationtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getVerifyTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['verify']) ? $data['verify'] : '');
        $list = $this->getVerifyList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setContracttimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setAuthorizationtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPublictimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setOrizationtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function staff()
    {
        return $this->belongsTo('app\store\model\staff\Staff', 'staff_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
